#tension_strain_limit: Tension strain limit.
#compress_strain_limit: Compression strain limit.
#is_both_control: Return true only when both strain limits are exceeded.
#ele_tag: Integer tag identifying element.
#sec_tag: Integer tag identifying section. Default is 0 for zero-length element.
proc is_Reach_Limit { tension_strain_limit compress_strain_limit is_both_control ele_tag {sec_tag 0} } {
    #The Element is Zero-Length or not
    if { $sec_tag == 0 } {
        #Define Variables at Section Corner
        set strain_1 [eleResponse $ele_tag section fiber 0 9999 strain]
        set strain_2 [eleResponse $ele_tag section fiber 0 -9999 strain]
        set strain_3 [eleResponse $ele_tag section fiber 9999 0 strain]
        set strain_4 [eleResponse $ele_tag section fiber -9999 0 strain]
    } else {
        #Define Variables at Section Corner
        set strain_1 [eleResponse $ele_tag section $sec_tag fiber 0 9999 strain]
        set strain_2 [eleResponse $ele_tag section $sec_tag fiber 0 -9999 strain]
        set strain_3 [eleResponse $ele_tag section $sec_tag fiber 9999 0 strain]
        set strain_4 [eleResponse $ele_tag section $sec_tag fiber -9999 0 strain]
    }
    
    #Get Maximum Strain in Tension
    set max_strain [get_Maximum $strain_1 $strain_2 $strain_3 $strain_4]
    #Get Minimum Strain in Compression
    set min_strain [get_Minimum $strain_1 $strain_2 $strain_3 $strain_4]

    #Check Limits
    if {$is_both_control} {
        if {($max_strain > $tension_strain_limit) && ($min_strain < $compress_strain_limit)} {
            return "true"
        } else {
            return "false"
        }
    } else {
        if {($max_strain > $tension_strain_limit) || ($min_strain < $compress_strain_limit)} {
            return "true"
        } else {
            return "false"
        }
    }
}

## Function to Get the Bigger Value
proc get_Max {value_1 value_2} {
    if { $value_1 > $value_2 } {
        return $value_1
    } else {
        return $value_2
    }
}

## Function to Get the Smaller Value
proc get_Min {value_1 value_2} {
    if { $value_1 > $value_2 } {
        return $value_2
    } else {
        return $value_1
    }
}

## Function to Get the Maximum Value
proc get_Maximum {value_1 value_2 value_3 value_4} {
    set value [get_Max $value_1 $value_2]
    set value [get_Max $value $value_3]
    return [get_Max $value $value_4]
}

## Function to Get the Mnimum Value
proc get_Minimum {value_1 value_2 value_3 value_4} {
    set value [get_Min $value_1 $value_2]
    set value [get_Min $value $value_3]
    return [get_Min $value $value_4]
}

